<template>
	<view class="topic-list-page">
		<detail-head type="home" url="../topic/topic"></detail-head>
		<view class="find-box">
			<view class="box-item" v-for="item in listData" :key="item.id"
				@click="$tool.navigateTo(`/pages/topic/detail?id=${item.id}&topicId=${topicID}`)">
				<view class="prod-img">
					<image class="img" :src="item.subPctureUrl" mode=""></image>
				</view>
				<view class="prod-info">
					<view class="name">{{item.worksName}}</view>
					<view class="other">
						<text class="number">#{{item.worksNum}}</text> <text class="price">￥{{item.price}}</text>
					</view>
					<view class="bay"></view>
				</view>
			</view>
		</view>
		<uni-load-more :contentText="contentText" @clickLoadMore="onClickLoadMore" :status="queryStatus">
		</uni-load-more>
	</view>
</template>

<script>
	import {
		getTopicWorksPage
	} from '../../request/topic-api.js'
	export default {
		data() {
			return {
				// 主题数组
				listData: [],
				// 列表查询参数
				params: {
					condition: "",
					pageNum: 0,
					pageSize: 6
				},
				topicID: 0,
				// 没有更多了
				isNoMore: false,
				// 加载状态
				queryStatus: 'more',
				// 各状态文字说明
				contentText: {
					contentdown: "点击加载更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		onLoad(option) {
			this.topicID = option.id
			this.params.condition = option.id
			this.onLoadListData()
		},
		methods: {
			// 点击加载更多
			onClickLoadMore() {
				if (!this.isNoMore) {
					this.onLoadListData()
				}
			},
			// 加载 数据
			async onLoadListData() {
				this.queryStatus = 'loading'
				this.params.pageNum += 1
				try {
					let {
						code,
						message,
						data
					} = await getTopicWorksPage(this.params)
					if (code === 200) {
						if (this.params.pageNum <= data.totalPage) {
							this.isNoMore = false
							this.listData.push(...data.list)
							this.queryStatus = 'more'
						} else {
							this.isNoMore = true
							this.queryStatus = 'noMore'
						}
					} else {
						this.queryStatus = 'more'
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch (err) {
					this.queryStatus = 'more'
					this.$tool.showErr(err)
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.topic-list-page {
		width: 100%;
		min-height: 100vh;
		margin-bottom: 40px;
		background: $layout-background-url;
		background-position: top left;
		background-size: 100% auto;
	}

	.find-box {
		margin: 20rpx 0;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 20rpx;

		.box-item {
			width: 334rpx;
			height: 500rpx;
			margin-bottom: 40rpx;
			background: linear-gradient(218deg, #3E454D 0%, #26252A 100%);
			box-shadow: -6rpx -6rpx 16rpx 0px rgba(70, 75, 86, 0.54), 6rpx 6rpx 16rpx 0px rgba(0, 0, 0, 0.83);
			border-radius: 32rpx;

			.prod-img {
				width: 334rpx;
				height: 334rpx;
				overflow: hidden;
				border-radius: 32rpx;
				background-color: #474A51;

				.img {
					width: 334rpx;
					height: 334rpx;
				}
			}


			.prod-info {
				width: 100%;
				min-height: 42px;
				margin-top: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				padding: 0 20rpx;
				position: relative;
				color: #BFCBCD;
				font-family: SourceHanSansCN-Bold, SourceHanSansCN;

				.name {
					width: 300rpx;
					font-size: 32rpx;
					font-weight: bold;
					line-height: 48rpx;
					margin-bottom: 20rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.other {
					width: 100%;
					font-size: 24rpx;
					font-weight: 400;
					color: #BFCBCD;
					line-height: 18px;
					margin-bottom: 28rpx;
					display: flex;
					align-items: center;

					.number {
						display: inline-block;
						min-width: 50rpx;
						height: 50rpx;
						text-align: center;
						line-height: 50rpx;
						max-height: 50rpx;
						border: 2rpx solid #FFBD47;
						border-radius: 16rpx 0 0 16rpx;
						padding: 0 8rpx;
					}

					.price {
						display: inline-block;
						height: 50rpx;
						background: #FFBD47;
						font-size: 24rpx;
						font-family: SourceHanSansCN-Bold, SourceHanSansCN;
						font-weight: bold;
						line-height: 50rpx;
						color: #1B1D24;
						padding: 0 10rpx;
						border: 2rpx solid #FFBD47;
						border-radius: 0 16rpx 16rpx 0;
					}
				}

				.bay {
					width: 50rpx;
					height: 50rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					position: absolute;
					right: 20rpx;
					bottom: 30rpx;
					box-shadow: -12rpx -12rpx 24rpx 0px rgba(66, 69, 76, 0.54), 12rpx 12rpx 24rpx 0px rgba(0, 0, 0, 0.83);
					border: 2rpx solid #FFBD47;
					border-radius: 50%;
					background: $common-right-url no-repeat;
					background-size: 60% 60%;
					background-position: center center;
					background-color: #1B1D24;
				}
			}
		}
	}
</style>
